import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';

import { $t } from '#/locales';

/** 产品详情列表的列定义 */
export function useDetailListColumns(
  showBusinessPrice: boolean,
): VxeTableGridOptions['columns'] {
  return [
    {
      field: 'productName',
      title: $t('views.crm.product.name'),
    },
    {
      field: 'productNo',
      title: $t('views.crm.product.no'),
    },
    {
      field: 'productUnit',
      title: $t('views.crm.product.unit'),
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CRM_PRODUCT_UNIT },
      },
    },
    {
      field: 'productPrice',
      title: $t('views.crm.product.price'),
      formatter: 'formatAmount2',
    },
    {
      field: 'businessPrice',
      title: $t('views.crm.product.detail.businessPrice'),
      formatter: 'formatAmount2',
      visible: showBusinessPrice,
    },
    {
      field: 'contractPrice',
      title: $t('views.crm.product.detail.contractPrice'),
      formatter: 'formatAmount2',
      visible: !showBusinessPrice,
    },
    {
      field: 'count',
      title: $t('views.crm.product.count'),
      formatter: 'formatAmount3',
    },
    {
      field: 'totalPrice',
      title: $t('views.crm.product.detail.totalPrice'),
      formatter: 'formatAmount2',
    },
  ];
}

/** 产品编辑表格的列定义 */
export function useProductEditTableColumns(): VxeTableGridOptions['columns'] {
  return [
    { type: 'seq', title: $t('views.common.seq'), minWidth: 50 },
    {
      field: 'productId',
      title: $t('views.crm.product.productId'),
      minWidth: 100,
      slots: { default: 'productId' },
    },
    {
      field: 'productNo',
      title: $t('views.crm.product.productNo'),
      minWidth: 150,
    },
    {
      field: 'productUnit',
      title: $t('views.crm.product.unit'),
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CRM_PRODUCT_UNIT },
      },
    },
    {
      field: 'productPrice',
      title: $t('views.crm.product.price'),
      minWidth: 100,
      formatter: 'formatAmount2',
    },
    {
      field: 'sellingPrice',
      title: $t('views.crm.product.sellingPrice'),
      minWidth: 100,
      slots: { default: 'sellingPrice' },
    },
    {
      field: 'count',
      title: $t('views.crm.product.count'),
      minWidth: 100,
      slots: { default: 'count' },
    },
    {
      field: 'totalPrice',
      title: $t('views.crm.product.totalPrice'),
      minWidth: 100,
      formatter: 'formatAmount2',
    },
    {
      title: $t('common.action'),
      width: 80,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
